home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-05-01 | 11.8 KB | 462 lines | [TEXT/MPS ] |
- // UViewServer.cp
- // Copyright © 1987-1991 by Apple Computer Inc. All rights reserved.
-
- #ifndef __STDIO__
- #include <StdIo.h>
- #endif
-
- #ifndef __UGEOMETRY__
- #include <UGeometry.h>
- #endif
-
- #ifndef __UWINDOW__
- #include <UWindow.h>
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include <UMacAppUtilities.h>
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include <UMacAppGlobals.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __USCROLLER__
- #include <UScroller.h>
- #endif
-
- #ifndef __UAPPLICATION__
- #include <UApplication.h>
- #endif
-
- #ifndef __UERRORMGR__
- #include <UErrorMgr.h>
- #endif
-
- #ifndef __UVIEWSERVER__
- #include <UViewServer.h>
- #endif
-
- //--------------------------------------------------------------------------------------------------
- // global declarations for globals defined in interface
- TViewServer* gViewServer;
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- pascal void TViewServer::Initialize(void) // override
- {
- inherited::Initialize();
-
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- pascal void TViewServer::IViewServer()
- {
- this->IObject();
-
- gViewServer = this; // set the global reference.
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- pascal void TViewServer::Free(void) // override
- {
- gViewServer = NULL; // NIL out the global reference.
-
- inherited::Free();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- pascal TWindow* TViewServer::NewPaletteWindow(short itsRsrcID,
- Boolean wantHScrollBar,
- Boolean wantVScrollBar,
- TDocument* itsDocument,
- TView* itsMainView,
- TView* itsPaletteView,
- short sizePalette,
- VHSelect whichWay)
-
- {
- TWindow * aWindow;
- TScroller * aScroller = NULL;
- FailInfo fi;
- VPoint itsSize;
- VPoint itsLocation;
- VRect sBarOffsets;
-
- VOLATILE(aWindow);
-
- aWindow = NewTWindow(itsRsrcID, itsDocument);
-
- (aWindow->fResizeLimits[topLeft])[whichWay] += sizePalette;
-
- if (fi.Try())
- {
-
- aWindow->AddSubView(itsPaletteView);
-
- itsLocation = gZeroVPt;
- itsLocation[whichWay] = sizePalette;
- if (wantHScrollBar || wantVScrollBar)
- {
- sBarOffsets = gZeroVRect;
- itsSize = aWindow->fSize;
- if (wantHScrollBar)
- {
- itsSize.v -= kSBarSizeMinus1;
- if (!wantVScrollBar)
- sBarOffsets.right = -kSBarSizeMinus1;
- }
- if (wantVScrollBar)
- {
- itsSize.h -= kSBarSizeMinus1;
- if (!wantHScrollBar)
- sBarOffsets.bottom = -kSBarSizeMinus1;
- }
- itsSize[whichWay] -= sizePalette;
-
- FailInfo fi2;
- aScroller = new TScroller;
- aScroller->IScroller(aWindow, itsLocation, itsSize, sizeRelSuperView, sizeRelSuperView, gZeroVPt, wantHScrollBar, wantVScrollBar);
- aScroller->fSBarOffsets = sBarOffsets;
- aScroller->AddSubView(itsMainView);
- }
- else
- aWindow->AddSubView(itsMainView);
-
- aWindow->SetTarget(itsMainView);
-
- // make frames be the right size
- aWindow->Resize(VPoint(aWindow->fWMgrWindow->portRect[botRight] - aWindow->fWMgrWindow->portRect[topLeft]), kDontInvalidate);
-
- fi.Success();
- }
- else // Recover
- {
- aWindow = (TWindow *)FreeIfObject(aWindow);
- fi.ReSignal(); // Optional. Omit to continue.
- }
-
- return aWindow;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- pascal TWindow* TViewServer::NewSimpleWindow(short itsRsrcID,
- Boolean wantHScrollBar,
- Boolean wantVScrollBar,
- TDocument* itsDocument,
- TView* itsView)
-
- {
- TWindow * aWindow;
- TScroller * aScroller = NULL;
- FailInfo fi;
- VPoint itsSize;
- VRect sBarOffsets;
-
- VOLATILE(aWindow);
-
- aWindow = NewTWindow(itsRsrcID, itsDocument);
-
- if (fi.Try())
- {
-
- if (wantHScrollBar || wantVScrollBar)
- {
- sBarOffsets = gZeroVRect;
- itsSize = aWindow->fSize;
- if (wantHScrollBar)
- {
- itsSize.v -= kSBarSizeMinus1;
- if (!wantVScrollBar)
- sBarOffsets.right = -kSBarSizeMinus1;
- }
- if (wantVScrollBar)
- {
- itsSize.h -= kSBarSizeMinus1;
- if (!wantHScrollBar)
- sBarOffsets.bottom = -kSBarSizeMinus1;
- }
- aScroller = new TScroller;
- aScroller->IScroller(aWindow, gZeroVPt, itsSize, sizeRelSuperView, sizeRelSuperView, gZeroVPt, wantHScrollBar, wantVScrollBar);
- aScroller->fSBarOffsets = sBarOffsets;
- if (itsView != NULL)
- aScroller->AddSubView(itsView);
- }
- else if (itsView != NULL)
- aWindow->AddSubView(itsView);
-
- aWindow->SetTarget(itsView);
-
- // make sure window and subviews are the right size
- aWindow->Resize(VPoint(aWindow->fWMgrWindow->portRect[botRight] - aWindow->fWMgrWindow->portRect[topLeft]), kDontInvalidate);
-
- fi.Success();
- }
- else // Recover
- {
- aWindow = (TWindow *)FreeIfObject(aWindow);
- fi.ReSignal(); // Optional. Omit to continue.
- }
-
- return aWindow;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- pascal TWindow* TViewServer::NewTWindow(short itsRsrcID,
- TDocument* itsDocument)
-
- {
- WindowPtr aWMgrWindow = NULL;
- TWindow * aWindow = NULL;
- Boolean canResize;
- Boolean canClose;
- FailInfo fi;
-
- VOLATILE(aWMgrWindow);
-
- aWMgrWindow = gApplication->GetRsrcWindow(NULL, itsRsrcID, canResize, canClose);
- // GetRsrcWindow signals Failure
-
- if (fi.Try())
- {
- aWindow = new TWindow;
- fi.Success();
- }
- else // Recover
- {
- aWMgrWindow = FreeIfWMgrWindow(aWMgrWindow, TRUE);
- fi.ReSignal(); // Optional. Omit to continue.
- }
-
- aWindow->IWindow(itsDocument, aWMgrWindow, canResize, canClose, TRUE);/* TRUE means can dispose
- wmgr window */
-
- return aWindow;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- pascal TWindow* TViewServer::NewTemplateWindow(short viewRsrcID,
- TDocument* itsDocument)
-
- {
- TWindow * theWindow = NULL;
- TView * theTarget = NULL;
- TView * aView = NULL;
-
- aView = this->DoCreateViews(itsDocument, NULL, viewRsrcID, gZeroVPt);
- if (aView != NULL)
- {
- if (qDebug && !(aView->IsMemberClass(GetClassIDFromName("TWindow"))))
- ProgramBreak("In NewTemplateWindow: Root view is not a window");
-
- theWindow = (TWindow *)aView;
-
- if (theWindow->fWMgrWindow != NULL)
- {
- Rect portRect(theWindow->fWMgrWindow->portRect);
- theWindow->Resize(VPoint(portRect.bottom - portRect.top, portRect.right - portRect.left), kDontInvalidate);
- }
- if (theWindow->fTargetID != kNoIdentifier)
- {
- theTarget = theWindow->FindSubView(theWindow->fTargetID);
- if (theTarget != NULL)
- theWindow->SetTarget(theTarget);
- else if (qDebug)
- ProgramBreak("The window has no view whose id is fTargetId.");
- }
- }
- return theWindow;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- pascal TView* TViewServer::DoCreateViews(TDocument* itsDocument,
- TView* parentView,
- short itsRsrcID,
- const VPoint& subviewOffset)
- {
- ViewRsrcHandle viewResource;
- SignedByte savedState;
- FailInfo fi;
- TView * firstView = NULL; // Assume the worst.
-
- VOLATILE(viewResource);
- VOLATILE(firstView);
-
- viewResource = (ViewRsrcHandle)GetResource('view', itsRsrcID);
- if (viewResource == NULL)
- {
- #if qDebug
- Str255 theString;
- ConcatNumber("Unable to find ‘view’ resource #", itsRsrcID, theString);
- ProgramBreak(theString);
- #endif
-
- FailNILResource((Handle)viewResource);
- }
-
- savedState = LockHandleHigh((Handle)viewResource);
-
- if (fi.Try())
- {
- short numViews = (**viewResource).numViews;
- IDType lastParentID = kNoIdentifier;
- TView * aView = parentView;
- TView * lastRoot = parentView;
- TView * lastParent = NULL;
-
- ViewTemplatePtr theViewInfo = &((**viewResource).theViews);// Initial setting. This pointer is bumped in the for loop below
- for (short i = 1; i <= numViews; ++i)
- {
- #if qDebugMsg
- if (gIntenseDebugging)
- ReportTemplate(*theViewInfo);
- #endif
-
- if (((long) theViewInfo->itsParentID) == ((long)kNoIdentifier))
- lastParent = parentView;
- else if (((long)theViewInfo->itsParentID) != ((long)lastParentID))
- {
- lastParent = aView; // Begin with last view created or parentView
- while ((lastParent != NULL) && (lastParent->fIdentifier != theViewInfo->itsParentID))
- lastParent = lastParent->fSuperView;
-
- if ((lastParent == NULL) && (lastRoot != NULL))
- if (aView != NULL)
- lastParent = aView->FindSubView(theViewInfo->itsParentID);
- else
- lastParent = lastRoot->FindSubView(theViewInfo->itsParentID);
-
- #if qDebug
- if (lastParent == NULL)
- ProgramBreak("Unable to find parent view for template");
- #endif
-
- }
- lastParentID = theViewInfo->itsParentID;
-
- if (((long)theViewInfo->itsSignature) == ((long)'incl'))
- {
- aView = this->DoCreateViews(itsDocument, lastParent, theViewInfo->u1.includeRsrcID, gZeroVPt);
- OffsetPtr((Ptr&)theViewInfo, sizeof(ViewTemplate) - sizeof(Str255) + sizeof(short));
- }
- else if (((long)theViewInfo->itsSignature) == ((long)'inc@'))
- {
- aView = this->DoCreateViews(itsDocument, lastParent, theViewInfo->u1.includeRsrcID, (const VPoint&) theViewInfo->u1.itsSubViewOffset);
- OffsetPtr((Ptr&)theViewInfo, sizeof(ViewTemplate) - sizeof(Str255) + sizeof(short) + sizeof(VPoint));
- }
- else
- aView = this->CreateAView(itsDocument, lastParent, (Ptr&) theViewInfo);
-
- if (aView == NULL)
- break;
- if (((subviewOffset.h != 0) || (subviewOffset.v != 0)) && (aView->fSuperView == parentView) && (parentView != NULL))
- aView->Locate(aView->fLocation + subviewOffset, kDontInvalidate);
-
- if (i == 1)
- {
- firstView = aView;
-
- if (aView->IsMemberClass(GetClassIDFromName("TWindow")) && (parentView == NULL))
- parentView = aView;
- }
-
- if ((lastRoot == NULL) && (aView != NULL) && (aView->fSuperView == NULL))
- lastRoot = aView;
-
- } // for
-
- HSetState((Handle) viewResource, savedState);
- fi.Success();
- }
- else // Recover
- {
- HSetState((Handle) viewResource, savedState);
-
- firstView = (TView *)FreeIfObject(firstView);
- }
-
- if (firstView)
- firstView->AdjustSize(); // Make sure size gets adjusted by the size determiners
-
- return firstView;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- pascal TView* TViewServer::CreateAView(TDocument* itsDocument,
- TView* itsSuperView,
- Ptr& itsParams)
-
- {
- TView * aView = NULL;
-
- ViewTemplatePtr params = (ViewTemplatePtr)(itsParams);
- Str255 className = params->u0.itsType; //!!! NOTE: Union
-
- if (className.IsEmpty())
- aView = (TView *)(NewStdObject(params->itsSignature));
- else
- {
- aView = (TView *)(NewObjectByClassName(className));
- if ((aView == NULL) && (GetClassIDFromName(className) == kNilClass))
- {
- #if qDebug
- ProgramBreak("The application doesn’t contain the class ‘" + className + ".’");
- #endif
-
- gErrorParm3 = className; // show name of class
- Failure(errMissingClass, 0);
- }
- }
-
- if (aView)
- aView->IRes(itsDocument, itsSuperView, itsParams);
- else
- FailNIL(aView);
-
- return aView;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADebug
-
- #if qDebugMsg
-
- pascal void TViewServer::ReportTemplate(const ViewTemplate& theViewData)
- {
- WrLblSig("signature", theViewData.itsSignature);
- fprintf(stderr, "\n");
- WrLblSig("itsParentID", theViewData.itsParentID);
- WrLblSig(", thisViewID", theViewData.thisViewID);
- fprintf(stderr, "\n");
- WrLblVPt("itsLocation", theViewData.itsLocation);
- WrLblVPt(", itsSize", theViewData.itsSize);
- fprintf(stderr, "itsHSizeDet == %3ld", (long)theViewData.itsHSizeDet);
- fprintf(stderr, ", itsVSizeDet == %3ld", (long)theViewData.itsVSizeDet);
- WrLblBoolean(", isEnabled ", theViewData.isEnabled);
- fprintf(stderr, "\n");
- fprintf(stderr, "---------- end of view ----------\n");
- }
- #endif
-
-